package com.bdmc.smokesensor.services;

import java.util.*;
import java.util.List;
import com.bdmc.smokesensor.dao.Rbac_FunctionJPA;
import com.bdmc.smokesensor.entity.Rbac_Function;
import com.bdmc.smokesensor.iservices.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

@Service
public class Rbac_FunctionService extends BaseService<Rbac_Function> implements IRbac_FunctionService {

    @Autowired
    private Rbac_FunctionJPA _funJPA;

    @Override
    public List<Rbac_Function> findAll() {
        List<Rbac_Function> list = _funJPA.findAll();
        return list;
    }

    @Override
    public Rbac_Function findOne(Example<Rbac_Function> example) {
        return _funJPA.findOne(example).orElse(null);
    }

    @Override
    public Rbac_Function findOneById(int id) {
        return _funJPA.findById(id).orElse(null);
    }

    @Override
    public Rbac_Function save(Rbac_Function d) {
        if (d.getId() < 1)
            d.setJoinDate(new Date());
        else
            d.setUpdateDate(new Date());
        return _funJPA.save(d);
    }

    @Override
    public void deleteById(int id) {
        _funJPA.deleteById(id);
    }

    @Override
    public List<Rbac_Function> GetParentFunction(int id) {
        return _funJPA.findByparentFunIdOrderByFunOrderAsc(id);
    }

    @Override
    public List<Rbac_Function> getFunctionByString(String ids) {
        //String sql ="call sp_split('1,2,3',',');select f.* from temp_split t inner join rbac_function f on f.id=t.col;";
        //return GetListBySql(sql, Rbac_Function.class);
        return _funJPA.getFunctionByString(ids);
    }


}